//获取应用实例
import {
  _globle
} from '../../utils/globle.js'
import LPage from '../../utils/lpage.js'
var navdata = require('/data/data.js')
import {
  getTaskData
} from './biz.js'
import lwx from '../../utils/lwx.js'

Page({

  _pageNo: 1,
  _pageSize: 5,
  _hasMore: true,
  data: {
    _islogin: false,
    imgUrls: [{
      url: '/images/index_banner.jpg'
    }],
    dot: 1,
    party: null,
    taskList: [],
    noMore: false,
    type: 'remain',
    selectStatus: false,
    pmanagementList: {
      title: '发货管理',
      management: [{
        name: '待发货',
        number: 25,
        url:'../cargoList/waitSend/waitSend'
      }, {
        name: '已发货',
        number: 78,
          url:'../cargoList/sendCargo/sendCargo'
      }]
    },
    peiHuoList: {
      title: '发货管理',
      management: [{
          name: '待发货',
          number: 25
        }, {
          name: '已发货',
          number: 78
        },
        {
          name: '已配货',
          number: 122
        }
      ]
    },
    number: {
      total: 30,
      dai: 18,
      yi: 15,
      bang: 10,
      shi: 5
    },
    noticeList: [{
        time: "2020：05：03",
        number: '25'
      },
      {
        time: "2020：08：12",
        number: '46'
      },
      {
        time: "2020：11：08",
        number: '73'
      }
    ]

  },
  onLoad: function() {
    this.getUserInfo();
    // this.loadVerifyList()
    wx.getSystemInfo({
      success: res => {
        // console.log(res)
        this.setData({
          windowHeight: res.windowHeight
        })
      },
    })
  },
  onShow: function() {
    this.getUserInfo();
    this._pageNo = 1
    wx.setNavigationBarTitle({
      title: _globle.user.companyName //修改title
    })
  },
  getNav: function() {
    let nav = []
    var sealArray = [];
    var pmArray = [];
    const type = _globle.user.roles;
    if (type) {
      for (let val of type) {
        if (navdata.hasOwnProperty(val)) {
          navdata[val].forEach(item => {
            if (item.title == '印章管理') {
              sealArray = sealArray.concat(item.navlist);
            } else if (item.title == '人员管理') {
              pmArray = item.navlist;
            }
          })
        }
      }
    }

    function unique(arr) {
      return Array.from(new Set(arr))
    }
    if (pmArray.length === 0) {
      nav = [{
        "title": "印章管理",
        navlist: unique(sealArray)
      }]
    } else {
      nav = [{
        "title": "印章管理",
        navlist: unique(sealArray)
      }, {
        "title": "人员管理",
        navlist: pmArray
      }];
    }
    return nav
  },
  switchStatus: function() {
    var selectStatus = !this.data.selectStatus;
    var name = this.data.selectStatus ? "办公" : "发货";
    this.setData({
      selectStatus: selectStatus,
    })
    wx.setTabBarItem({
      index: 1,
      text: name,
    })
  },
  //去登录
  goLogin: function() {
    wx.navigateTo({
      url: '../center/login/login',
    })
  },
  getUserInfo: function() {
    lwx.request({
      url: "user.info",
    }).then(res => {
      console.log('res' + res)
      if (res.data.code == '0') {
        _globle.user = res.data.partys;
        wx.setNavigationBarTitle({
          title: res.data.partys.companyName //修改title
        })
        _globle.user.isLogin = true;
        this.setData({
          _islogin: true,
          party: res.data.partys,
          nav: this.getNav(),
        })
      } else {
        _globle.user.isLogin = false;
        this.setData({
          _islogin: false
        })
        console.log('333333');
      }
    }).catch(err => {
      _globle.user.isLogin = false;
      this.setData({
        _islogin: false
      })
      console.log('err' + err);
    })
  },
  scanCargo:function(){
    wx.navigateTo({
      url: '../cargoList/scanSendCargo/scanSendCargo',
    })
  }
})